package com.kaikeba.wx.Filter;

import com.kaikeba.bean.User;
import com.kaikeba.util.UserUtil;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter({"/index.html"})
public class FilterUser implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest)req;
        HttpServletResponse response = (HttpServletResponse)resp;
        User wxUser = UserUtil.getWxUser(request.getSession());
        if(wxUser!=null) {
            chain.doFilter(request, response);
        }else{
            //跳转页面
            response.sendRedirect("login.html");
        }
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
